/**
 * Copyright (c) 2022 Beijing Jiaotong University
 * PhotLab is licensed under [Open Source License].
 * You can use this software according to the terms and conditions of the [Open Source License].
 * You may obtain a copy of [Open Source License] at: [https://open.source.license/]
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 *
 * See the [Open Source License] for more details.
 *
 * Author: Zhenjie Wei, Qing'ao Zhang
 * Created: Mar. 12, 2023
 * Supported by: National Key Research and Development Program of China
 */

const fs = require('fs')
import { commandManager } from "@/common/cmd/manager"

const mainRef = {
    theme: false,
    sysToolbarList: [
        {
            title: '文件',
            type: 'file',
            options: [
                {
                    display: 'row',
                    size: 'large',
                    list: [
                        {
                            display: 'column',
                            label: '新建',
                            icon: 'new-file',
                            id: '',
                            arrow: true,
                            fn: async () => {
                                // fs.mkdirSync
                                const fileList = await fs.readdirSync('D:\\code\\mlyGitLibrary\\phot-design\\src\\assets\\')
                                console.log(fileList)
                                if (fileList.indexOf('newFile.text')) {
                                    console.log('文件已存在')
                                    return false
                                }
                                await fs.writeFileSync('D:\\code\\mlyGitLibrary\\phot-design\\src\\assets\\newFile.text','', function(error: any) {
                                    if(error){
                                        console.log(error)
                                    }else{
                                        console.log('新建文件成功')
                                    }
                                })
                                commandManager.executeCommand('file.newFile')
                            }
                        },
                    ]
                },
                {
                    display: 'row',
                    size: 'large',
                    list: [
                        {
                            display: 'column',
                            label: '保存',
                            icon: 'save',
                            id: '',
                            arrow: true,
                            fn: async () => {
                                
                            }
                        },
                    ]
                },
                {
                    display: 'column',
                    size: 'small',
                    list: [
                        {
                            display: 'row',
                            label: '打开',
                            icon: 'folder-open',
                            id: '',
                            fn: () => {
                                console.log(fs.readdirSync('D:\\code\\mlyGitLibrary\\phot-design'))
                                fs.readFile('D:\\code\\mlyGitLibrary\\phot-design\\package.json',function(error: any, data: any){
                                    if(error){
                                        console.log('读取文件失败')
                                    }else{
                                        console.log(data.toString())
                                    }
                                })

                                commandManager.executeCommand('file.openFolder')
                            }
                        },
                        {
                            display: 'row',
                            label: '关闭',
                            icon: 'folder-close',
                            id: '',
                            fn: () => commandManager.executeCommand('file.closeFolder')
                        },
                        {
                            display: 'row',
                            label: '退出',
                            icon: 'quit',
                            id: '',
                            fn: () => commandManager.executeCommand('file.quit')
                        },
                    ]
                },
                {
                    display: 'column',
                    size: 'small',
                    list: [
                        {
                            display: 'row',
                            label: '打印',
                            icon: 'print',
                            id: '',
                            fn: () => commandManager.executeCommand('main.file.print')
                        },
                        {
                            display: 'row',
                            label: '帮助',
                            icon: 'help',
                            id: '',
                            arrow: true,
                            fn: () => commandManager.executeCommand('main.file.help')
                        },
                        {
                            display: 'row',
                            label: '设置',
                            icon: 'setting',
                            id: '',
                            fn: () => commandManager.executeCommand('main.file.setting')
                        },
                    ]
                },
            ]
        },
        {
            title: '剪切板',
            type: 'clipboard',
            options: [
                {
                    display: 'row',
                    showText: true,
                    size: 'large',
                    list: [
                        {
                            display: 'column',
                            label: '粘贴',
                            icon: 'stickup',
                            id: '',
                            arrow: true,
                            fn: () => commandManager.executeCommand('main.clipboard.stickup')
                        }
                    ]
                },
                {
                    display: 'column',
                    showText: true,
                    size: 'small',
                    list: [
                        {
                            display: 'row',
                            label: '复制',
                            icon: 'copy',
                            id: '',
                            fn: () => commandManager.executeCommand('main.clipboard.copy')
                        },
                        {
                            display: 'row',
                            label: '剪切',
                            icon: 'cut',
                            id: '',
                            fn: () => commandManager.executeCommand('main.clipboard.cut')
                        },
                        {
                            display: 'row',
                            label: '删除',
                            icon: 'clean',
                            id: '',
                            fn: () => commandManager.executeCommand('main.clipboard.clean')
                        },
                    ]
                },
            ]
        },
        {
            title: '文本编辑',
            type: 'text-mode'
        },
        {
            title: '视图',
            options: [
                {
                    display: 'column',
                    showText: true,
                    size: 'small',
                    list: [
                        {
                            display: 'row',
                            label: '还原',
                            icon: 'restore',
                            id: '',
                            fn: () => commandManager.executeCommand('main.view.restore')
                        },
                        {
                            display: 'row',
                            label: '放大',
                            icon: 'zoom-in',
                            id: '',
                            fn: () => commandManager.executeCommand('main.view.zoomIn')
                        },
                    ]
                },
                {
                    display: 'column',
                    showText: true,
                    size: 'small',
                    list: [
                        {
                            display: 'row',
                            label: '平移',
                            icon: 'translate-45',
                            id: '',
                            fn: () => commandManager.executeCommand('main.view.translate')
                        },
                        {
                            display: 'row',
                            label: '缩小',
                            icon: 'zoom-out',
                            id: '',
                            fn: () => commandManager.executeCommand('main.view.zoomOut')
                        },
                    ]
                },
            ]
        },
        {
            title: '组件编辑',
            options: [
                {
                    display: 'row',
                    showText: true,
                    size: 'large',
                    list: [
                        {
                            display: 'column',
                            label: '编辑参数',
                            icon: 'edit',
                            id: '',
                            fn: () => commandManager.executeCommand('main.editor.edit')
                        },
                        {
                            display: 'column',
                            label: '在PhotCode打开',
                            icon: 'open-in-photcode',
                            id: '',
                            fn: () => commandManager.executeCommand('main.editor.openInCode')
                        },
                        {
                            display: 'column',
                            label: '启动PhotCode',
                            icon: 'start-photcode',
                            id: '',
                            fn: () => commandManager.executeCommand('main.editor.startCode')
                        },
                    ]
                },
            ]
        },
        {
            title: '仿真',
            options: [
                {
                    display: 'row',
                    showText: true,
                    size: 'large',
                    list: [
                        {
                            display: 'column',
                            label: '运行',
                            icon: 'play',
                            id: '',
                            fn: () => commandManager.executeCommand('main.simulate.run')
                        },
                        {
                            display: 'column',
                            label: '暂停',
                            icon: 'pause',
                            id: '',
                            fn: () => commandManager.executeCommand('main.simulate.pause')
                        },
                        {
                            display: 'column',
                            label: '终止',
                            icon: 'stop',
                            id: '',
                            fn: () => commandManager.executeCommand('main.simulate.stop')
                        },
                    ]
                },
            ]
        },
        {
            title: '分析器',
            options: [
                {
                    display: 'row',
                    showText: true,
                    size: 'large',
                    list: [
                        {
                            display: 'column',
                            label: '结果可视化',
                            icon: 'visualization',
                            id: '',
                            fn: () => commandManager.executeCommand('analyze.visualization')
                        },
                        {
                            display: 'column',
                            label: '新窗口',
                            icon: 'new-window',
                            id: '',
                            fn: () => commandManager.executeCommand('analyze.newWindow')
                        },
                        {
                            display: 'column',
                            label: '关闭所有',
                            icon: 'file-close-all',
                            id: '',
                            fn: () => commandManager.executeCommand('analyze.closeAll')
                        },
                    ]
                },
            ]
        },
        {
            title: '系统变量',
            options: [
                {
                    display: 'row',
                    showText: true,
                    size: 'large',
                    list: [
                        {
                            display: 'column',
                            label: '系统变量设置',
                            icon: 'a-lianxuboDFBjiguangqi8',
                            id: '',
                            fn: () => commandManager.executeCommand('system.variables')
                        }
                    ]
                },
            ]
        },
    ],
    passiveDeviceToolbarList: [
        {
            title: '文件',
            type: 'file',
            options: [
                {
                    display: 'row',
                    size: 'large',
                    list: [
                        {
                            display: 'column',
                            label: '新建',
                            icon: 'xinjian',
                            id: '1',
                            fn: () => {
                                console.log('新建')
                            }
                        },
                    ]
                },
                {
                    display: 'row',
                    size: 'large',
                    list: [
                        {
                            display: 'column',
                            label: '保存',
                            icon: 'baocun',
                            id: '2',
                            fn: () => {
                                console.log('保存')
                            }
                        },
                    ]
                },
                {
                    display: 'column',
                    showText: true,
                    size: 'small',
                    list: [
                        {
                            display: 'row',
                            label: '打开',
                            icon: 'dakai',
                            id: '3',
                            fn: () => {
                                console.log('打开')
                            }
                        },
                        {
                            display: 'row',
                            label: '关闭',
                            icon: 'folder-close',
                            id: '4',
                            fn: () => {
                                console.log('关闭')
                            }
                        },
                        {
                            display: 'row',
                            label: '退出',
                            icon: 'tuichu',
                            id: '5',
                            fn: () => {
                                console.log('退出')
                            }
                        },
                    ]
                }
            ]
        },
        {
            // TODO: phot-ui create block-type = simulation-mode
            title: '模拟区域',
            type: 'simulation-mode'
        },
        {
            title: '材料库管理',
            options: [
                {
                    display: 'row',
                    showText: true,
                    size: 'large',
                    list: [
                        {
                            display: 'column',
                            label: '材料库',
                            icon: 'cailiaoku',
                            id: '1',
                            fn: () => commandManager.executeCommand('materialLibrary.open')

                        },
                        {
                            display: 'column',
                            label: '新增材料',
                            icon: 'xinzengcailiao',
                            id: '2',
                            fn: () => commandManager.executeCommand('materialLibrary.openAdd')
                        },
                    ]
                }
            ]
        },
        {
            title: '器件设置',
            options: [
                {
                    display: 'row',
                    showText: true,
                    size: 'large',
                    list: [
                        {
                            display: 'column',
                            label: '光源',
                            icon: 'guangyuanicon',
                            id: '1',
                            fn: () => {
                                console.log('打开默认光源')
                            },
                            // 下拉选项光源类型列表
                            dataList: [
                                {
                                    label: '点光源',
                                    value: 'point source',
                                    fn: () => {
                                        console.log('打开点光源')
                                    },
                                    // 可加入点光源图标
                                    // icon: ''
                                },
                                {
                                    label: '线光源',
                                    value: 'line source',
                                    fn: () => {
                                        console.log('打开线光源')
                                    },
                                    // 可加入线光源图标
                                    // icon: ''

                                },
                                {
                                    label: '面光源',
                                    value: 'plane source',
                                    fn: () => {
                                        console.log('打开面光源')
                                    },
                                    // 可加入面光源图标
                                    // icon: ''
                                }
                            ]
                        },
                        {
                            display: 'column',
                            label: '波导',
                            icon: 'bodaoicon',
                            id: '2',
                            fn: () => {
                                console.log('打开默认波导')
                            },
                            // 下拉选项波导类型列表
                            dataList: [
                                {
                                    label: '矩形直波导',
                                    value: 'rectangle',
                                    fn: () => {
                                        console.log('打开矩形直波导')
                                    },
                                    // 可加入图标
                                    // icon: ''
                                },
                                {
                                    label: 'S波导',
                                    value: 's-bend',
                                    fn: () => {
                                        console.log('打开S波导')
                                    },
                                    // 可加入图标
                                    // icon: ''

                                },
                                {
                                    label: 'Y型波导',
                                    value: 'y-splitter',
                                    fn: () => {
                                        console.log('打开面光源')
                                    },
                                    // 可加入图标
                                    // icon: ''
                                },
                                {
                                    label: '方向耦合器',
                                    value: 'directional coupler',
                                    fn: () => {
                                        console.log('打开方向耦合器')
                                    },
                                    // 可加入图标
                                    // icon: ''
                                },
                                {
                                    label: '环形谐振腔',
                                    value: 'ring resonator',
                                    fn: () => {
                                        console.log('打开环形谐振腔')
                                    },
                                    // 可加入图标
                                    // icon: ''
                                },
                                {
                                    label: '多模干涉耦合器',
                                    value: 'mmi',
                                    fn: () => {
                                        console.log('打开多模干涉耦合器')
                                    },
                                    // 可加入图标
                                    // icon: ''
                                },
                                {
                                    label: '马赫曾德干涉仪',
                                    value: 'mzi',
                                    fn: () => {
                                        console.log('打开马赫曾德干涉仪')
                                    },
                                    // 可加入图标
                                    // icon: ''
                                },
                                {
                                    label: '圆波导',
                                    value: 'circle',
                                    fn: () => {
                                        console.log('打开圆波导')
                                    },
                                    // 可加入图标
                                    // icon: ''
                                },
                                {
                                    label: '四分之一圆弧',
                                    value: 'arc',
                                    fn: () => {
                                        console.log('打开四分之一圆弧')
                                    },
                                    // 可加入图标
                                    // icon: ''
                                }
                            ]

                        },
                        {
                            display: 'column',
                            label: '监视器',
                            icon: 'jianshiqiicon',
                            id: '3',
                            fn: () => {
                                console.log('打开默认监视器')
                            },
                            // 下拉选项监视器类型列表
                            dataList: [
                                {
                                    label: '线监视器',
                                    value: 'line detector',
                                    fn: () => {
                                        console.log('打开线监视器')
                                    },
                                    // 可加入图标
                                    // icon: ''
                                },
                                {
                                    label: '矩形监视器',
                                    value: 'block detector',
                                    fn: () => {
                                        console.log('打开矩形监视器')
                                    },
                                    // 可加入图标
                                    // icon: ''
                                },

                            ]
                            
                        }
                    ]
                }
            ]

        },
        {
            title: '仿真',
            options: [
                {
                    display: 'row',
                    showText: true,
                    size: 'large',
                    list: [
                        {
                            display: 'column',
                            label: '运行',
                            icon: 'kaishi',
                            id: '1',
                            fn: () => {
                                console.log('运行')
                            }
                        },
                        {
                            display: 'column',
                            label: '终止',
                            icon: 'a-zhongzhi',
                            id: '2',
                            fn: () => {
                                console.log('终止')
                            }
                        },
                        {
                            display: 'column',
                            label: '任务管理',
                            icon: 'renwutiaodu',
                            id: '3',
                            fn: () => {
                                console.log('打开任务管理')
                            }
                        },
                    ]
                },
            ],
        },
    ],
    setting: {} as any
}
const mainData = {
    mainRef
}
export default mainData